package com.asm.slidingmenu;

import com.asm.slidingmenu.Backup.ASM_Backup;
import com.dspl.asmswd.R;

import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ASM_Settings_Fragment extends Fragment {
	
	public ASM_Settings_Fragment(){}
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
		
		
        View rootView = inflater.inflate(R.layout.asm_fragment_setting, container, false);
        Button crtbackup = (Button)rootView.findViewById(R.id.btncrestbackup);
        
        crtbackup.setOnClickListener(new View.OnClickListener() 
        {
			
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub
				try

				{

					ASM_Backup db =new ASM_Backup(getActivity());
					db.exportDB();

				}

				catch (Exception ex)

				{

					Toast.makeText(getActivity(), "Backup Error!",Toast.LENGTH_SHORT).show();

				}
				
			}
		});
        
         
        return rootView;
    }
	
	private void restoreLogin(final Context context){
		// get prompts.xml view
		LayoutInflater layoutInflater = LayoutInflater.from(context);

		View promptView = layoutInflater.inflate(R.layout.admin_login, null);

		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
		alertDialogBuilder.setTitle("Please enter your admin password");
		// set prompts.xml to be the layout file of the alertdialog builder
		alertDialogBuilder.setView(promptView);

		final EditText input = (EditText) promptView.findViewById(R.id.userInput);

		// setup a dialog window
		alertDialogBuilder
				.setCancelable(false)
				.setPositiveButton("Login", new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {

								
								if(input.getText().toString().equals("ga128")){
									
//									Intent myIntent = new Intent(context,
//											ImportActivity.class);
//									myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
//											| Intent.FLAG_ACTIVITY_NEW_TASK);
//									startActivityForResult(myIntent, 0);
									
								}else{
									
//									Toast.makeText(getApplicationContext(), "Invalid Password", 
//											Toast.LENGTH_LONG).show();
								}
							}
						})
				.setNegativeButton("Cancel",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,	int id) {
								dialog.cancel();
							}
						});

		// create an alert dialog
		AlertDialog alertD = alertDialogBuilder.create();

		alertD.show();
	}
	 public boolean onKeyDown(int keyCode, KeyEvent event) {
	     if(keyCode==KeyEvent.KEYCODE_BACK)
	         Toast.makeText(getActivity(), "Use Home Button",      
	      Toast.LENGTH_LONG).show();

	     return false;
	        // Disable back button..............
	 }
}
